package com.ruoyi.event.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.event.domain.bo.EventZqBo;
import com.ruoyi.event.domain.vo.EventZqVo;
import com.ruoyi.event.domain.vo.UserCurrentSjskZqVo;
import com.ruoyi.event.service.IEventZqService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 人员转期
 *
 * @author strongme
 * @date 2023-02-16
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/event/zq")
public class EventZqController extends BaseController {

    private final IEventZqService iEventZqService;

    /**
     * 获取人员转期信息
     *
     * @param sjskId
     * @return
     */
    @GetMapping("getUserZqInfo")
    public R<UserCurrentSjskZqVo> getUserZqInfo(Long sjskId) {
        return R.ok(iEventZqService.getUserSjskZqInfo(sjskId));
    }

    /**
     * 查询人员转期列表
     */
    @GetMapping("/list")
    public TableDataInfo<EventZqVo> list(EventZqBo bo, PageQuery pageQuery) {
        return iEventZqService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出人员转期列表
     */
    @Log(title = "人员转期", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(EventZqBo bo, HttpServletResponse response) {
        List<EventZqVo> list = iEventZqService.queryList(bo);
        ExcelUtil.exportExcel(list, "人员转期", EventZqVo.class, response);
    }

    /**
     * 获取人员转期详细信息
     *
     * @param zqId 主键
     */
    @GetMapping("/{zqId}")
    public R<EventZqVo> getInfo(@NotNull(message = "主键不能为空")
                                @PathVariable Long zqId) {
        return R.ok(iEventZqService.queryById(zqId));
    }

    /**
     * 新增人员转期
     */
    @Log(title = "人员转期", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody EventZqBo bo) {
        return toAjax(iEventZqService.insertByBo(bo));
    }

    /**
     * 修改人员转期
     */
    @Log(title = "人员转期", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody EventZqBo bo) {
        return toAjax(iEventZqService.updateByBo(bo));
    }

    /**
     * 删除人员转期
     *
     * @param zqIds 主键串
     */
    @Log(title = "人员转期", businessType = BusinessType.DELETE)
    @DeleteMapping("/{zqIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] zqIds) {
        return toAjax(iEventZqService.deleteWithValidByIds(Arrays.asList(zqIds), true));
    }
}
